<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;


class MessageResource extends JsonResource
{
    public function toArray($request): array
    {
        $data = parent::toArray($request);
        if($data['user_id'] == 0 && Carbon::parse($data['created_at'])->diffInDays(Carbon::now()) >= 1){
            $data['read'] = 1;
        }
        $data['created_at'] = Carbon::parse($data['created_at'])->rawFormat('M j, Y g:i A');
        return $data;
    }
}
